import 'package:flutter/material.dart';

class PopScopePage extends StatelessWidget {
  const PopScopePage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false, // 是否允许自动弹出 true: 可以使用手势来退出。false:不可以
      onPopInvokedWithResult: (didPop, result) async {
        if (didPop) return;
        // 你的返回拦截逻辑
        final shouldPop = await showDialog(
          context: context,
          builder: (ctx) => AlertDialog(
            title: Text('确认退出？'),
            actions: [
              TextButton(
                onPressed: () => Navigator.pop(ctx, false),
                child: Text('取消'),
              ),
              TextButton(
                onPressed: () => Navigator.pop(ctx, true),
                child: Text('确认'),
              ),
            ],
          ),
        );
        if (shouldPop ?? false) {
          Navigator.of(context).pop();
        }
      },
      child: Scaffold(
        appBar: AppBar(
          title: const Text('Hello World'),
        ),
        body: Center(
          child: Padding(
            padding: EdgeInsets.all(8.0),
            child: Text('订单编号：27118fea-3663-41f9-b908-856381418917'.fixAutoLines()),
          ),
        ),
      ),
    );
  }
}

///
/// 防止文字自动换行
///
extension FixAutoLines on String {
  String fixAutoLines() {
    return Characters(this).join('\u{200B}');
  }
}
